
LoginManager = {

    // 初始化
    init : function () {
        gnet.setServerUrl("http://192.168.252.182:8111");

    /*
     http://cdn.jq.yaowan.com/winner11.html?skey=ba44eb0401&serverid=ytest&xml=yaowan_20130511_1.xml&api=http://183.61.135.48:8005/
     获取服务器地址 http://183.61.135.48:8005/sytest
     */
    },


    // 登陆
    login : function (account, password) {
        gnet.sendHttp("login", [account, password], LoginManager.onLoginReturn);
    },
    

    onLoginReturn : function (data) {
    if(data.result == 'ok') {
        cc.log('登陆成功了');
        
        var sk = data.data[0];
        var role = data.data[1];
        cc.log('session_key:' + sk + '   role id:'+role);
        // 设置SessionKey
        gnet.setSessionKey(sk);
        // 判断是否有角色
        if(!role) {
            //* 出错啦
            return;
        }

        gnet.sendHttp("get_main_data", null, LoginManager.onMainDataReturn);
        }
    },

    onMainDataReturn : function (data) {
        if(data.result == 'ok') {
            cc.log('获取MainData');
            DataManager.player = data.data.player;
            DataManager.playerTanks = data.data.car_data;
            DataManager.playerItems = data.data.item_data;
            DataManager.missionData = data.data.mission_data;

            UIManager.changeSceneMain();
        }
    },

    /*
    // 创建角色
    createRole : function (name, race) {
        gnet.sendHttp("login_cr", [name, race], this.onCreateRoleReturn);
    },

    onCreateRoleReturn : function (data) {
    if(data['result']=='ok') {
            cc.log('onCreateRoleReturn login ok');
        }
    },
*/

};
